package 链表;

import common.ListNode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tmh
 * @date 2024/11/22 19:02
 * @description
 */
public class T142环形链表II {
    public ListNode detectCycle(ListNode head) {
        Map<ListNode, Integer> map = new HashMap<>();
        int index = 0;
        while (head != null) {
            if (map.containsKey(head)){
                return head;
            }
            map.put(head,index++);
            head=head.next;
        }
        return null;
    }
}
